﻿#include "phnt/phnt_windows.h"
#include "phnt/phnt.h"
#include <iostream>
// 打印所有的dll模块内容。当然其中也包括exe本身。
void printAllDLLModule(){
    auto peb = (PEB*)NtCurrentTeb()->ProcessEnvironmentBlock;
    // 获取Ldr并遍历InLoadOrderModuleList来查找模块
    if (peb && peb->Ldr) {
        PLIST_ENTRY moduleList = &peb->Ldr->InLoadOrderModuleList;
        PLIST_ENTRY entry = moduleList->Flink;

        while (entry != moduleList) {
            // 获取当前模块的LDR_DATA_TABLE_ENTRY结构
            PLDR_DATA_TABLE_ENTRY currentModule = CONTAINING_RECORD(entry, LDR_DATA_TABLE_ENTRY, InLoadOrderLinks);

            // 打印模块名称和基址
            std::wcout << "Module Name: " << currentModule->BaseDllName.Buffer << std::endl;
            std::wcout << "Base Address: " << currentModule->DllBase << std::endl;

            // 继续下一个模块
            entry = entry->Flink;
        }
    } else {
        std::cerr << "Failed to retrieve PEB or PEB->Ldr is NULL." << std::endl;
    }
    return;
}

int main(){
    printAllDLLModule();
    return 0;
}
